<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GCS Results</title>
</head>
    <body>
<?php

$query = "san francisco";
$front_end = "YOUR_frontend";
$collection = "YOUR_collection";
$restrictBy=" inmeta:brand=acme inmeta:price:10..20";
$gsa_query = "http://YOUR_GSA/search?q=".urlencode($query)."&client=".$front_end."&output=xml_no_dtd&getfields=*&site=".$collection."&start=0"."&as_q=".urlencode($restrictBy);

$ch = curl_init($gsa_query);

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$results=curl_exec($ch);

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($http_code == 200)
{
	$doc = new DOMDocument();
	$doc->loadXML($results);	
	$xpath = new DOMXPath($doc);
	
	$n_totalResults = $xpath->query("/GSP/RES/M");
	$totalResult =  $n_totalResults->item(0)->textContent;
	echo "<b>totalResults:</b> ".$totalResult."<br/>";
	
	$n_responseTime = $xpath->query("/GSP/TM");
	$responseTime =  $n_responseTime->item(0)->textContent;
	echo "<b>responseTime:</b> ".$responseTime."<br/>";
	
	$nl_queryparam = $xpath->query("/GSP/PARAM");
	foreach ($nl_queryparam as $r) {
		$name = $r->getAttribute("name");
		$value = $r->getAttribute("value");
		//echo "query parameter ".$name."-->".$value."<br/>";
	}
		
	$nl_spellings = $xpath->query("/GSP/Spelling/Suggestion");
	foreach ($nl_spellings as $r) {
		$spellingsuggest = $r->getAttribute("q");
		echo "<b>spelling suggest:</b> ".$spellingsuggest."<br/>";
	}
	
	$nl_keymatch = $xpath->query("/GSP/GM");
	foreach ($nl_keymatch as $r) {
		$n_url = $xpath->query("GL",$r);
		$n_title = $xpath->query("GD",$r);
		$url = $n_url->item(0)->textContent;
		$title = $n_title->item(0)->textContent;
		echo "keymatch parameter ".$title."-->".$url."<br/>";
	}	
	
	$nl_oneboxresults = $xpath->query("/GSP/ENTOBRESULTS/OBRES/MODULE_RESULT");
	foreach ($nl_oneboxresults as $r) {
		$n_title = $xpath->query("Title",$r);
		$title = $n_title->item(0)->textContent;
		echo "<b>onebox results:</b> ".$title."<br/>";
		$nl_fields = $xpath->query("Field",$r);
		foreach ($nl_fields as $f) {
			$name = $f->getAttribute("name");
			$value = $f->nodeValue;
			echo "&nbsp;&nbsp;&nbsp;".$name."-->".$value."<br/>";
		}
	}


        $nl_facets = $xpath->query("/GSP/RES/PARM/PMT");
        foreach ($nl_facets as $f) {
                $facet_name = $f->getAttribute("NM");
                $facet_type = $f->getAttribute("IR");
                echo "<b>Facet:</b> ".$facet_name."<br/>";
                $f_values = $xpath->query("PV",$f);
                foreach ($f_values as $fv) {
                  if ($facet_type=="1") {
                     $low = $fv->getAttribute("L");
                     $high = $fv->getAttribute("H");
                     $count = $fv->getAttribute("C");
                     echo "&nbsp;&nbsp;&nbsp;&nbsp;".$low."---->".$high."  : ".$count."<br/>";
                  }
                  else {
                     $name = $fv->getAttribute("V");
                     $count = $fv->getAttribute("C");
                     echo "&nbsp;&nbsp;&nbsp;&nbsp;".$name."---->".$count."<br/>";
                  }
		}
        }
		
	$nl_results = $xpath->query("/GSP/RES/R");
	foreach ($nl_results as $r) {
		$n_url = $xpath->query("U",$r);		
		$n_title = $xpath->query("T",$r);
		$nl_meta = $xpath->query("MT",$r);
		$url =  $n_url->item(0)->textContent;
		$title =  $n_title->item(0)->textContent;
		echo "<br/><a href='>".$url."'>".$title."</a><br/>";
                foreach ($nl_meta as $m) {
                  $name = $m->getAttribute("N");
                  $value = $m->getAttribute("V");
                  echo "&nbsp;&nbsp;&nbsp;".$name."-->".$value."<br/>";
		}
	}
}
?>
    </body>
</html>
